package com.dingwei.superiordiary.adapter.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.dingwei.superiordiary.R;
import com.dingwei.superiordiary.app.MyApplication;
import com.dingwei.superiordiary.bean.AddressBookBean;
import com.dingwei.superiordiary.bean.FIndUserBean;
import com.jude.easyrecyclerview.adapter.BaseViewHolder;
import com.jude.easyrecyclerview.adapter.RecyclerArrayAdapter;
import com.lihao.baselibrary.base.BaseActivity;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by lihao on 2018/1/11.
 */

public class AddressBookAdapter extends RecyclerArrayAdapter<AddressBookBean.DataBean> {

    public interface attentionInterFace {
        void attention(int position);
    }

    private attentionInterFace attentionInterFace;

    public void attentionInterfaceListener(attentionInterFace listener) {
        attentionInterFace = listener;

    }


    public AddressBookAdapter(Context context) {
        super(context);
    }

    @Override
    public BaseViewHolder OnCreateViewHolder(ViewGroup parent, int viewType) {
        return new MyCarePersonlHolder(parent);
    }


    class MyCarePersonlHolder extends BaseViewHolder<AddressBookBean.DataBean> {


        @Bind(R.id.img_head)
        ImageView imgHead;
        @Bind(R.id.tv_nick_name)
        TextView tvNickName;
        @Bind(R.id.tv_level)
        TextView tvLevel;
        @Bind(R.id.tv_idiograph)
        TextView tvIdiograph;
        @Bind(R.id.tv_attention)
        TextView tvAttention;

        public MyCarePersonlHolder(ViewGroup parent) {
            super(parent, R.layout.item_care_personl);
            ButterKnife.bind(this, itemView);
        }

        @Override
        public void setData(AddressBookBean.DataBean data) {
            super.setData(data);
            tvNickName.setText(data.nickname);
            Glide.with(BaseActivity.context)
                    .load(data.portrait)
                    .apply(MyApplication.headOptions)
                    .into(imgHead);
            tvLevel.setText("LV." + data.level);
            tvIdiograph.setText(data.idiograph + "");
            if (data.attentioned==0) {
                tvAttention.setText("+关注");
                tvAttention.setTextColor(ContextCompat.getColor(BaseActivity.context, R.color.theme_color));
                tvAttention.setBackgroundResource(R.drawable.theme_line_bg);
            } else {
                tvAttention.setText("已关注");
                tvAttention.setTextColor(ContextCompat.getColor(BaseActivity.context, R.color.white));
                tvAttention.setBackgroundResource(R.drawable.theme_bg);
            }
           tvAttention.setOnClickListener(new View.OnClickListener() {
               @Override
               public void onClick(View view) {
                   if (attentionInterFace!=null){
                       attentionInterFace.attention(getDataPosition());
                   }
               }
           });
        }
    }
}
